<extend name="Base/common"/>
<block name="Content">
    <div class="am-cf am-padding-top">
        <div class="am-fl am-cf">
            <notempty name="bannerModel">
                <i class="am-icon-pencil-square-o"></i>
                <else/><i class="am-icon-plus-square"></i>
            </notempty>
            <strong class="am-text-primary am-text-lg">
                <notempty name="bannerModel">
                    编辑<else/>新增
                </notempty>活动效果图
            </strong>
        </div><hr data-am-widget="divider" class="am-divider am-divider-default" />
    </div>
    <form method="post" class="am-form" action="{:U('saveAction')}">
        <div class="am-tabs-bd">
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                   活动名称
                </div>
				<div class="am-u-sm-8 am-u-md-3">
					<input type="text" name="name" class="am-form-field am-input-sm" 
                        	value="{$bannerModel['name']}"/>
                </div>
                <div class="am-hide-sm-only am-u-md-7">
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                   活动开关
                </div>
				<div class="am-u-sm-8 am-u-md-3">
					<input type="radio" name="activity" value="1"/>开<input type="radio" name="activity" value="2"/>关 
                </div>
                <div class="am-hide-sm-only am-u-md-7">
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                   活动统一编码
                </div>
				<div class="am-u-sm-8 am-u-md-3">
					<input type="text" name="random" id="random" class="am-form-field am-input-sm" 
                        	value="{$bannerModel['random']}" pattern="^[0-9a-zA-Z]{4}$"/>
                </div>
                <div class="am-hide-sm-only am-u-md-7">
              		*支持字母、数字组合的四位随机数，同一活动、不同轮播图的编码须一致，不同活动编码不同。
                </div>
            </div>
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                   优惠券金额
                </div>
				<div class="am-u-sm-8 am-u-md-3">
					<input type="text" name="money" id="money" min="0" step="1" class="am-form-field am-input-sm" 
                        	value="{$bannerModel['money']}"/>
                </div>
                <div class="am-hide-sm-only am-u-md-7">
                	单位：元。目前支持两种优惠方式：满减和定额优惠。满减优惠时（如满100减20），配置值形式为：100-20；定额优惠时（如优惠20），配置值形式为：20
                </div>
            </div>
            
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                    内容描述
                </div>
                <div class="am-u-sm-8 am-u-md-8">
                    <textarea rows="8" name="content" id="content" class="am-input-sm" required>{$bannerModel['content']}</textarea>
                </div>
                <div class="am-hide-sm-only am-u-md-2">
                </div>
            </div>
            
            <div class="am-g am-margin-top">
                <div class="am-u-sm-4 am-u-md-2 am-text-right">
                    效果图
                </div>
                <div class="am-u-sm-8 am-u-md-3">
                    <div class="am-form-group am-form-file">
                        <input type="file" name="pict_cover" id="pict_cover"/>
						<input type="hidden" name="att_id" id="att_id" value="{$bannerModel['att_id']}"/>
                    </div>
                    <div id="photo_thumbnail">
                        <notempty name="bannerModel['att_id']">
                            <figure class="am-thumbnail">
                            
                            	<img src="{$bannerModel['fullpath']}">
                                
                            </figure>
                        </notempty>
                    </div>
                </div>
                <div class="am-hide-sm-only am-u-md-7">
                	建议值：首页轮播图长：宽=9:5
                </div>
            </div>
            
        </div>
            
        <div class="am-margin">
            <button type="submit" class="am-btn am-btn-success am-btn-xs ajax-post" target-form="am-form">
                提交保存
            </button>
            <button type="button" class="am-btn am-btn-secondary am-btn-xs" onclick="javascript:history.back(-1);return false;">
                返回列表
            </button>
            <input type="hidden" value="{$bannerModel['banner_id']}" name="banner_id" id="banner_id"/>
        </div>
    </form>
</block>
<block name="script">
    <script src="__PUBLIC__/Common/js/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/Common/js/ueditor/ueditor.config.js" type="text/javascript"></script>
    <script src="__PUBLIC__/Common/js/ueditor/ueditor.all.min.js" type="text/javascript"></script>
    <script src="__PUBLIC__/Common/js/ueditor/lang/zh-cn/zh-cn.js" type="text/javascript"></script>
    
    <script type="text/javascript">
                   
    	Think.setValue('activity',{$bannerModel.activity|default=2});
        
        UE.getEditor("content",{
	        toolbars:[[
	        "fullscreen", '|', 'undo', 'redo', "|","bold", "italic", "underline", 'fontborder', 
	        'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch',
	        'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 
	        'insertunorderedlist', 'selectall', 'cleardoc', "|", 
	        'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
	        'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
	        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'insertimage']],
	        wordCount:false,enableAutoSave:false,elementPathEnabled:false
		});
    
      	//上传图片
        /* 初始化上传插件 */
        $("#pict_cover").uploadify({
            "height": 30,
            "width": 120,
            "swf": "__PUBLIC__/Common/js/uploadify/uploadify.swf",
            "fileObjName": "download",
            "buttonText": "上传头像",
            "uploader": "{:U('Attachment/uploadPhoto',array('session_id'=>session_id()))}",
            "fileSizeLimit":'{$fileSize}B',
            'fileTypeExts': '*.jpg; *.png; *.gif',
            "onUploadSuccess": uploadPicture,
            "onSelectError":uploadify_onSelectError,
            "onUploadError":uploadify_onUploadError,
            'onFallback': function(){
                alert('未检测到兼容版本的Flash.');
            }
        });

        function uploadPicture(file, data){
        	
            var data = $.parseJSON(data);
            var src = '';

            if (data.status) {
                $("#att_id").val(data.att_id);
                src = data.fullpath;
                $("#photo_thumbnail").html('<figure class="am-thumbnail"><img src="' + src + '"/></figure>');
            }else {
                updateAlert(data.info);
                setTimeout(function(){
                    $('#top-alert').find('button').click();
                    $(that).removeClass('disabled').prop('disabled', false);
                }, 1500);
            }
        }

    </script>
</block>
